<?php
/**
 * This example is simply to demonstrate the ping function
 * 
 * @author StudioCloud International Inc.
 * @version 1.0
 * @copyright Copyright 2010, StudioCloud International Inc.
 * @package Example
 * 
 */ 
 
$result = "";
//Check to see if any POST variables were passed and if the appropriate button was clicked
if ($_POST && $action="Submit") {
	
	//This is your apikey that can be retreived from the StudioCloud 3.0 program
	$apikey = "ENTER_APIKEY_HERE";
	
	//This is your apikeynumber that can be retreived from the StudioCloud 3.0 program
	$apikeynumber = "ENTER_APIKEYNUMBER_HERE";
		
	//This is the actual function that you want to call.  In this case, ping is the test method to make sure everything is working.
	$method = "ping";
	
	//The format that you want the response in.  The default is xml but in this case you want json
	$format = "json";
	
	//The url including all of the variables
    $url = "https://studiocloud.org/platform/Client.php?method=" . $method . "&format=" . $format . "&apikey=" . $apikey . "&apikeynumber=" . $apikeynumber . "&pingText=" . urlencode($_POST["pingText"]);

	//Utilizes the Client URL Library (CURL). Please see http://us3.php.net/manual/en/book.curl.php
    $curl_handle=curl_init();
    curl_setopt($curl_handle,CURLOPT_URL,$url);
    curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
    curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
    $buffer = curl_exec($curl_handle);
    curl_close($curl_handle);

    if (!empty($buffer)) {
    	//Uses the json_decode function.  Please see http://us3.php.net/manual/en/function.json-decode.php
        $obj = json_decode($buffer);
        $result = $obj->message;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
    <head>
        <title>Ping</title>
    </head>
    <body>
        <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                Text: <input type="text" name="pingText"/><br/>
                <input type="submit" name="action" value="Submit"/>
        </form>
        <?php
        if ($_POST && $action="Submit") {
                print "<h1>Result</h1>";
                print $result;
        }
        ?>
    </body>
</html>